package org.example.statemachine.enums;

import lombok.Getter;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 订单状态枚举
 */
@Getter
public enum OrderStatus {
    // 待支付，待发货，待收货，已完成
    WAIT_PAYMENT(1, "待支付"),
    WAIT_DELIVER(2, "待发货"),
    WAIT_RECEIVE(3, "待收货"),
    FINISH(4, "已完成");
    private Integer key;
    private String desc;
    private static Map<Integer,OrderStatus>map=
            Stream.of(OrderStatus.values())
                            .collect(Collectors.toMap(OrderStatus::getKey, Function.identity(), (k1, k2) -> k2));

    OrderStatus(Integer key, String desc) {
        this.key = key;
        this.desc = desc;
    }
    public static OrderStatus getByKey(Integer key) {
        return map.get(key);
    }
}


